 //
//  YZMStockQuotePanelView.m
//  YZMicroStock
//
//  Created by wangminhong on 16/4/12.
//  Copyright © 2016年 cqjr. All rights reserved.
//

#import "YZMStockQuotePanelView.h"
#import "YZMEntrustQueueView.h"
#import "YZMTrendView.h"
#import "YZMTrendItem.h"
#import "YZMTrendPacket.h"
#import "YZClient.h"
#import "YZMStockRealModel.h"
#import "YZMKLineView.h"
#import "YZMKLinePacket.h"
#import "YZMKLineItem.h"
#import "NSNumber+Utils.h"
#import <DateTools/DateTools.h>
#import "YZMStockHandicapView.h"
#import "YZMStockBuyInfoView.h"
#import "YZMOneStockBuyInfoView.h"

@interface YZMStockQuotePanelView()<UIScrollViewDelegate>

@property (nonatomic, strong) UISegmentedControl *segment;
@property (nonatomic, strong) UIScrollView *scrollView;

@property (nonatomic, strong) YZMEntrustQueueView *queueView;
@property (nonatomic, strong) YZMTrendView *trendView;
@property (nonatomic, strong) YZMTrendPacket *trendPacket;

@property (nonatomic, strong) YZMKLineView *kLineView;
@property (nonatomic, strong) YZMKLinePacket *kLinePacket;
@property (nonatomic, strong) YZMKLinePacket *weekKlinePacket;
@property (nonatomic, strong) YZMKLinePacket *monthKlinePacket;

@property (nonatomic, copy) NSString  *stockCode;
@property (nonatomic, assign) BOOL stopFlag;
@property (nonatomic, strong) YZMStockHandicapView *handicapView;

//@property (nonatomic, strong) YZMStockBuyInfoView *buyInfoView;
@property (nonatomic, strong) YZMOneStockBuyInfoView *oneBuyInfoView;
@property (nonatomic, assign) YZM_TRADE_TYPE tradeType;

@property (nonatomic, strong) YZMKLineView *weekKlineView;
@property (nonatomic, strong) YZMKLineView *monthKlineView;



@end

@implementation YZMStockQuotePanelView

- (instancetype)initWithFrame:(CGRect)frame andTradeType:(YZM_TRADE_TYPE)tradeType {
    
    self = [super initWithFrame:frame];
    if (self) {
        
        self.tradeType = tradeType;
        self.trendPacket = [[YZMTrendPacket alloc] init];
        self.kLinePacket = [[YZMKLinePacket alloc] init];
        self.weekKlinePacket = [[YZMKLinePacket alloc]init];
        self.monthKlinePacket = [[YZMKLinePacket alloc]init];
        [self createObjects];
    }
    
    return self;
}

- (void)awakeFromNib{
    [super awakeFromNib];
    self.trendPacket = [[YZMTrendPacket alloc] init];
    self.kLinePacket = [[YZMKLinePacket alloc] init];
    self.weekKlinePacket = [[YZMKLinePacket alloc]init];
    self.monthKlinePacket = [[YZMKLinePacket alloc]init];
    [self createObjects];
}


- (void)updateWithStockCode:(NSString *)code{
    
    self.stockCode = code;
    
    [self.trendPacket clearData];
    [self.trendView clearData];
    [self.kLinePacket clearData];
    [self.weekKlinePacket clearData];
    [self.monthKlinePacket clearData];
    [self.kLineView clearData];
    [self.queueView clearData];
}

- (void)refreshData{
    
    if (![self.trendPacket lastItem]) {
        
        [self requestToLoadTrend];
    }
    
    if (!self.kLinePacket.hasData) {
        
        [self requestToLoadKLine];
    }
    
    if (!self.weekKlinePacket.hasData) {
        
        [self week_requestToLoadKLine];
    }
    
    if (!self.monthKlinePacket.hasData) {
        
        [self month_requestToLoadKLine];
    }
    
}

#pragma mark -- network

- (void)requestToLoadTrend
{
    __weak typeof(&*self) safeSelf = self;
    NSString *beginTimeStr = nil;
    YZMTrendItem *lastItem = [self.trendPacket lastItem];
    if (lastItem) {
        beginTimeStr = [NSString stringWithFormat: @"%lld", lastItem.time];
    }
    NSString *code = [self codeAllaysValidate];
    [YZClient qt_getTrendInfoWithStockCode: code andBegin: beginTimeStr success:^(NSURLResponse *response, id responseObject) {
        YZGeneralResultModel *result = responseObject;
        
        if (result.success) {
            
            YZMTrendItem *newItem = [result.data lastObject];
            if (![newItem.code isEqualToString: safeSelf.stockCode]) {
                return ;
            }
            
            YZMTrendItem *currentLast = [safeSelf.trendPacket lastItem];
            if (currentLast) {
                [safeSelf.trendPacket updateFromItems: result.data];
            }
            else
            {
                [safeSelf.trendPacket setOriginItems: result.data];
            }
            [safeSelf.trendView updateFromDataPacket: safeSelf.trendPacket];
        }
    } failure:^(NSError *error) {
        NSLog(@"%@:%@", error.localizedDescription, error.localizedFailureReason);
        [error yz_showMessage];
    }];
}

- (void)requestToLoadKLine
{
    __weak typeof(&*self) safeSelf = self;
    NSDate *nowDate = [NSDate date];
    NSDate *startDate  = nil;
    BOOL append = self.kLinePacket.hasData;
    if (append) {
        startDate = [nowDate dateBySubtractingDays: 1];
    }
    else
    {
        startDate = [nowDate dateBySubtractingMonths: 4];
    }
    NSString *leTimeStr = [NSString stringWithFormat: @"%.0lf", startDate.timeIntervalSince1970 * 1000.0];
    NSString *geTimeStr =  [NSString stringWithFormat: @"%.0lf", nowDate.timeIntervalSince1970 * 1000.0];
    NSString *code = [self codeAllaysValidate];
    [YZClient qt_getKlineInfoWithStockCode: code andBegin: leTimeStr andEnd: geTimeStr success:^(NSURLResponse *response, id responseObject) {
        YZGeneralResultModel *result = responseObject;
        
        if (result.success) {
            YZMKLineItem *newItem = [result.data lastObject];
            if (![newItem.code isEqualToString: safeSelf.stockCode]) {
                return ;
            }
            
            if (append) {
                [safeSelf.kLinePacket updateFromItems: result.data];
            }
            else
            {
                [safeSelf.kLinePacket setOriginItems: result.data];
            }
            [safeSelf.kLineView updateFromDataPacket: safeSelf.kLinePacket];
//            [safeSelf.weekKlineView updateFromDataPacket:safeSelf.kLinePacket];
//            [safeSelf.monthKlineView updateFromDataPacket:safeSelf.kLinePacket];
        }
    } failure:^(NSError *error) {
        NSLog(@"%@:%@", error.localizedDescription, error.localizedFailureReason);
        [error yz_showMessage];
    }];
}

- (void)week_requestToLoadKLine
{
    __weak typeof(&*self) safeSelf = self;
    BOOL append = self.weekKlinePacket.hasData;

    NSString *code = [self codeAllaysValidate];
    [YZClient qt_getKlineInfoWithStockCode:code andType:@"weekKline" success:^(NSURLResponse *response, id responseObject) {
        
        YZGeneralResultModel *result = responseObject;
        if (result.success) {
            YZMKLineItem *newItem = [result.data lastObject];
            if (![newItem.code isEqualToString:safeSelf.stockCode]) {
                
                return;
            }
            
            if (append) {
                [safeSelf.weekKlinePacket updateFromItems: result.data];
            }
            else
            {
                [safeSelf.weekKlinePacket setOriginItems: result.data];
            }
            
            [safeSelf.weekKlineView updateFromDataPacket: safeSelf.weekKlinePacket];
        }
    } failure:^(NSError *error) {
        
        [error yz_showMessage];
    }];
}

- (void)month_requestToLoadKLine
{
    __weak typeof(&*self) safeSelf = self;
    BOOL append = self.monthKlinePacket.hasData;
    
    NSString *code = [self codeAllaysValidate];
    [YZClient qt_getKlineInfoWithStockCode:code andType:@"monthKline" success:^(NSURLResponse *response, id responseObject) {
        
        YZGeneralResultModel *result = responseObject;
        if (result.success) {
            YZMKLineItem *newItem = [result.data lastObject];
            if (![newItem.code isEqualToString:safeSelf.stockCode]) {
                
                return;
            }
            
            if (append) {
                [safeSelf.monthKlinePacket updateFromItems: result.data];
            }
            else
            {
                [safeSelf.monthKlinePacket setOriginItems: result.data];
            }
            
            [safeSelf.monthKlineView updateFromDataPacket: safeSelf.monthKlinePacket];
        }
    } failure:^(NSError *error) {
        
        [error yz_showMessage];
    }];
}

- (void)segmentValueChanged: (UIControl *)segment
{
    [self updateScrollViewFromSegment];
//    if (!self.stopFlag) {
//        [self refreshData];
//    }
}

- (void)updateScrollViewFromSegment
{
    if (_block) {
        _block(self.segment.selectedSegmentIndex);
    }
    float screenWidth = [UIScreen mainScreen].bounds.size.width;
    [self.scrollView setContentOffset:CGPointMake(screenWidth*self.segment.selectedSegmentIndex, 0) animated:YES];
}

#pragma mark -- ui

- (void)createObjects
{
    UIView *bgView = [[UIView alloc] init];
    bgView.backgroundColor = [YZMAppStyle colorForMain];
    [self addSubview:bgView];
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.equalTo(self);
        make.height.mas_equalTo(44);
    }];
    
    if (self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK || self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_D || self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_YLB || self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_SIM) {
        self.segment = [[UISegmentedControl alloc] initWithItems: @[@"分时", @"日K",@"周K",@"月K",@"盘口"]];
    }else{
        self.segment = [[UISegmentedControl alloc] initWithItems: @[@"分时", @"日K",@"周K",@"月K"]];
    }
    [bgView addSubview: self.segment];
    self.tintColor = [UIColor clearColor];
    NSDictionary* selectedTextAttributes = @{NSFontAttributeName:[YZMAppStyle mediumSizeFont],
                                             NSForegroundColorAttributeName:[YZMAppStyle colorForIconColor]};
    [self.segment setTitleTextAttributes:selectedTextAttributes forState:UIControlStateSelected];
    NSDictionary* unselectedTextAttributes = @{NSFontAttributeName:[YZMAppStyle mediumSizeFont],
                                               NSForegroundColorAttributeName:[YZMAppStyle colorForMainTextColor]};
    [self.segment setTitleTextAttributes:unselectedTextAttributes forState:UIControlStateNormal];
    
    self.segment.selectedSegmentIndex = 0;
    [self.segment addTarget: self action: @selector(segmentValueChanged:) forControlEvents: UIControlEventValueChanged];
    [self.segment setEnabled: YES forSegmentAtIndex: 0];
    [self.segment setEnabled: YES forSegmentAtIndex: 1];
    [self.segment setEnabled: YES forSegmentAtIndex: 2];
    [self.segment setEnabled: YES forSegmentAtIndex: 3];
    [self.segment mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(bgView);
        make.left.equalTo(bgView).offset(15);
        make.right.equalTo(bgView).offset(-15);
        make.centerY.equalTo(bgView);
    }];
    
    float heightForSV = 260+145;
    CGFloat subSpace = 15 + 145;
    if (self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_D ) {
        
//        heightForSV = 260 + 184 + 145 + 55;
//        subSpace = 15 + 184 + 145 + 55;
    }else if (self.tradeType==YZM_TRADE_TYPE_FOR_A_STOCK_ONE) {
        heightForSV = 260 + 260 + 100;
        subSpace = 15 + 260 + 150;
    }else if (self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_FREE){
        heightForSV = 260 + 260 + 100 + 40;
        subSpace = 15 + 260 + 150 - 10;
    }
 
    
    self.scrollView = [[UIScrollView alloc] init];
    [self addSubview: self.scrollView];
    self.scrollView.pagingEnabled = YES;
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.delegate = self;
    self.scrollView.scrollEnabled = NO;
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_bottom);
        make.left.right.width.height.equalTo(self);
        make.height.mas_equalTo(heightForSV);
    }];
    
    self.queueView = [[YZMEntrustQueueView alloc] init];
    [self.scrollView addSubview: self.queueView];
    [self.queueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.scrollView);
        make.bottom.equalTo(self.scrollView).offset(-(15 + 184));
        make.left.equalTo(self.scrollView).offset(ScreenWidth-100-15);
        make.width.mas_equalTo(100);
    }];
    
    self.trendView = [[YZMTrendView alloc] init];
    [self.scrollView addSubview: self.trendView];
    [self.trendView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.scrollView);
        make.right.equalTo(self.queueView.mas_left).offset(-10);
        make.top.equalTo(self.scrollView);
        make.height.equalTo(self.scrollView).offset(-subSpace);
    }];
    
    self.trendView.userInteractionEnabled = YES;
    self.trendView.tag = 100;
    UITapGestureRecognizer *trendTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)];
    trendTap.numberOfTapsRequired = 2;
    [self.trendView addGestureRecognizer:trendTap];
    
    self.kLineView  = [[YZMKLineView alloc] init];
    [self.scrollView addSubview: self.kLineView];
    [self.kLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.scrollView).offset(ScreenWidth);
        make.top.equalTo(self.scrollView);
        make.height.equalTo(self.scrollView).offset(-subSpace);
        make.width.mas_equalTo(ScreenWidth);
    }];
    
    self.kLineView.userInteractionEnabled = YES;
    self.kLineView.tag = 101;
    UITapGestureRecognizer *kLineTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];
    kLineTap.numberOfTapsRequired = 2;
    [self.kLineView addGestureRecognizer:kLineTap];
    
    self.weekKlineView  = [[YZMKLineView alloc] init];
    [self.scrollView addSubview: self.weekKlineView];
    [self.weekKlineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.scrollView).offset(ScreenWidth*2);
        make.top.equalTo(self.scrollView);
        make.height.equalTo(self.scrollView).offset(-subSpace);
        make.width.mas_equalTo(ScreenWidth);
    }];
    
    self.weekKlineView.userInteractionEnabled = YES;
    self.weekKlineView.tag = 102;
    UITapGestureRecognizer *weekkLineTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];
    [self.weekKlineView addGestureRecognizer:weekkLineTap];
    
    self.monthKlineView  = [[YZMKLineView alloc] init];
    [self.scrollView addSubview: self.monthKlineView];
    [self.monthKlineView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK || self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_YLB || self.tradeType ==YZM_TRADE_TYPE_FOR_A_STOCK_SIM || self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_D) {
            make.left.equalTo(self.scrollView).offset(ScreenWidth*4);
        } else {
            make.left.equalTo(self.scrollView).offset(ScreenWidth*3);
        }
        make.top.right.equalTo(self.scrollView);
        make.height.equalTo(self.scrollView).offset(-subSpace);
        make.width.mas_equalTo(ScreenWidth);
    }];
    
    self.monthKlineView.userInteractionEnabled = YES;
    self.monthKlineView.tag = 103;
    UITapGestureRecognizer *monthkLineTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];
    [self.monthKlineView addGestureRecognizer:monthkLineTap];
    
//    if (self.tradeType ==YZM_TRADE_TYPE_FOR_A_STOCK_SIM ) {//|| self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_YLB
//        self.handicapView  = [[YZMStockHandicapView alloc] init];
//        [self addSubview:self.handicapView];
//        [self.handicapView mas_makeConstraints:^(MASConstraintMaker *make) {
//
//            make.left.right.equalTo(self.scrollView);
//            make.top.equalTo(self.trendView.mas_bottom).offset(14);
//            make.height.equalTo(self.scrollView).offset(-subSpace);
//        }];
//    }
    
    if (self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK || self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_YLB || self.tradeType ==YZM_TRADE_TYPE_FOR_A_STOCK_SIM || self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_D) {
        self.handicapView  = [[YZMStockHandicapView alloc] initWithType:1];
        [self.scrollView  addSubview:self.handicapView];
        [self.handicapView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.scrollView).offset(ScreenWidth*4);
            make.top.right.equalTo(self.scrollView);
            make.height.equalTo(self.scrollView).offset(-subSpace);
            make.width.mas_equalTo(ScreenWidth);
            //            make.left.right.equalTo(self.scrollView);
            //            make.top.equalTo(self.trendView.mas_bottom).offset(14);
            //            make.height.mas_equalTo(100);
        }];
    }
    
    if (self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_D) {
        
        self.handicapView  = [[YZMStockHandicapView alloc] initWithType:1];
        [self.scrollView  addSubview:self.handicapView];
        [self.handicapView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.scrollView).offset(ScreenWidth*4);
            make.top.right.equalTo(self.scrollView);
            make.height.equalTo(self.scrollView).offset(-subSpace);
            make.width.mas_equalTo(ScreenWidth);
//            make.left.right.equalTo(self.scrollView);
//            make.top.equalTo(self.trendView.mas_bottom).offset(14);
//            make.height.mas_equalTo(100);
        }];
        
//        self.buyInfoView = [[YZMStockBuyInfoView alloc] init];
//        [self addSubview:self.buyInfoView];
//        [self.buyInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
//            
//            make.left.right.equalTo(self.scrollView);
//            make.top.equalTo(self.handicapView.mas_bottom);
//            make.height.mas_equalTo(184+55);
//        }];
        
    }else if(self.tradeType==YZM_TRADE_TYPE_FOR_A_STOCK_ONE){
        
        self.handicapView  = [[YZMStockHandicapView alloc] init];
        [self addSubview:self.handicapView];
        [self.handicapView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.right.equalTo(self.scrollView);
            make.top.equalTo(self.trendView.mas_bottom).offset(14);
            make.height.mas_equalTo(100);
        }];
        
        self.oneBuyInfoView = [[YZMOneStockBuyInfoView alloc] init];
        self.oneBuyInfoView.defaultModel=self.defaultMode;
        [self addSubview:self.oneBuyInfoView];
        [self.oneBuyInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.right.equalTo(self.scrollView);
            make.top.equalTo(self.handicapView.mas_bottom);
            make.height.mas_equalTo(300);
        }];
    }else if (self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_FREE){
        self.handicapView  = [[YZMStockHandicapView alloc] init];
        [self addSubview:self.handicapView];
        [self.handicapView mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.left.right.equalTo(self.scrollView);
            make.top.equalTo(self.trendView.mas_bottom);
            make.height.mas_equalTo(90);
        }];
        
        self.oneBuyInfoView = [[YZMOneStockBuyInfoView alloc] init];
        self.oneBuyInfoView.defaultModel=self.defaultMode;
        self.oneBuyInfoView.isFree = YES;
        [self addSubview:self.oneBuyInfoView];
        [self.oneBuyInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.scrollView);
            make.top.equalTo(self.handicapView.mas_bottom);
            make.height.mas_equalTo(350);
        }];
    }
}

- (CGFloat)heightForFreeExInfo{
    CGFloat height = [@"本次免费体验活动所获得的盈利分成将以红包的形式发放至您的红包账户，用于抵扣交易综合费" boundingRectWithSize:CGSizeMake(ScreenWidth - 30, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0]} context:nil].size.height;
    return height;
}

-(void)rotation:(UITapGestureRecognizer *)sender{
    
    NSInteger senderIndex = sender.view.tag;
    [YZMCMInstance presentViewControllerWithName:@"rotation" andParams:@{@"stockCode":self.stockCode,@"index":@(senderIndex)}];
}


- (void)setSchemeModel:(YZMMyStackModel *)schemeModel {
    
    _schemeModel = schemeModel;
//    self.buyInfoView.schemeModel = schemeModel;
}

- (void)updateRealInfo:(YZMStockRealModel *)realInfo{
    
    self.trendPacket.closePrice  = realInfo.lastClosePrice;
    self.trendPacket.highPrice = realInfo.highPrice;
    self.trendPacket.lowPrice = realInfo.lowPrice;
    [self.trendView updateFromDataPacket: self.trendPacket];
    self.queueView.realItem = realInfo;
    self.handicapView.realInfo = realInfo;
    if ( [@(realInfo.price) isEqualWithDouble:0.0]) {
        self.stopFlag = YES;
    }else{
        self.stopFlag = NO;
    }
    
    [self refreshData];
    
    if (self.tradeType == YZM_TRADE_TYPE_FOR_A_STOCK_D) {
        
//        self.buyInfoView.realInfo = realInfo;
//        self.buyInfoView.schemeModel = self.schemeModel;
//        self.buyInfoView.inforModel = self.inforModel;
//        [self.buyInfoView updateFromData];
    }
    if (self.tradeType==YZM_TRADE_TYPE_FOR_A_STOCK_ONE) {
        
        NSInteger amountNumber=[@(self.defaultMode.totalMoney/realInfo.price/self.defaultMode.tradingCountRatio/100.0).rfString integerValue]*100;
        
        self.oneBuyInfoView.amountNumber=amountNumber;
        [[NSNotificationCenter defaultCenter]postNotificationName:@"ONEYUANAMOUNT" object:nil userInfo:@{@"oneyamount":@(amountNumber)}];
        self.oneBuyInfoView.defaultModel=self.defaultMode;
        [self.oneBuyInfoView updateDate];
    }else if (self.tradeType==YZM_TRADE_TYPE_FOR_A_STOCK_FREE){
        NSInteger amountNumber=[@(self.defaultMode.totalMoney/realInfo.price/self.defaultMode.tradingCountRatio/100.0).rfString integerValue]*100;
        
        self.oneBuyInfoView.amountNumber=amountNumber;
        [[NSNotificationCenter defaultCenter]postNotificationName:@"ONEYUANAMOUNT" object:nil userInfo:@{@"oneyamount":@(amountNumber)}];
        self.oneBuyInfoView.defaultModel=self.defaultMode;
        [self.oneBuyInfoView updateDate];
    }
}

- (void)updateCurrentIndex:(NSInteger)currentIndex{
    
    self.segment.selectedSegmentIndex = currentIndex;
    [self updateScrollViewFromSegment];
}

- (NSString *)codeAllaysValidate
{
    NSString *code = self.stockCode;
    if (code.length == 0) {
        code = @"SH601318";
    }
    return code;
}



@end
